package com.tian.controller.api;

import com.tian.common.CommonResult;
import com.tian.dto.exchange.CheckExchangeCodeReqDto;
import com.tian.dto.exchange.CheckExchangeCodeRespDto;
import com.tian.dto.exchange.ExchangeCodePreUseReqDto;
import com.tian.service.ExchangeCodeService;
import com.tian.service.ExchangeCodeValidateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * {@code @description:} 用户使用兑换码接口
 *
 * @author tianwc 公众号：Java后端技术全栈
 * 在线刷题 1200+java面试题和1000+篇技术文章：<a href="https://woaijava.cc/">博客地址</a>
 * {@code @date:} 2024-11-24 17:07
 * {@code @version:} 1.0
 */
@RestController
@RequestMapping("/market/api/exchange/code")
@Api(tags = "兑换码校验 控制器")
public class ExchangeCode4ApiController {
    @Resource
    private ExchangeCodeValidateService exchangeCodeValidateDecoratorService;
    @Resource
    private ExchangeCodeService exchangeCodeService;
    /**
     * 校验兑换码
     */
    @PostMapping("/validate")
    public CommonResult<CheckExchangeCodeRespDto> validateCode(@RequestBody CheckExchangeCodeReqDto checkExchangeCodeReqDto) {
        return exchangeCodeValidateDecoratorService.validateCode(checkExchangeCodeReqDto);
    }

    @ApiOperation(value = "计算优惠金额", notes = "通过优惠券编码和订单金额计算出优惠金额")
    @ApiResponses({@ApiResponse(code = 200000, message = "计算成功")})
    @PostMapping("/pre/use")
    public CommonResult<String> preUse(@RequestBody ExchangeCodePreUseReqDto exchangeCodePreUseReqDto) {
        return exchangeCodeService.preUse(exchangeCodePreUseReqDto);
    }
}
